package com.icez.base_util_library.extension

import android.content.Context
import com.icez.base_util_library.CompressUtil
import com.icez.base_util_library.DateStoreUtil
import com.icez.base_util_library.NumberUtil
import java.io.File

/**
 * 字符串转double
 * 
 * @author Icez
 */
fun String?.toSEDouble():Double{
    return NumberUtil.instance.stringToDouble(this)
}

/**
 *  字符串转Int
 * 
 * @author Icez
 */
fun String?.toSEInt():Int{
    return NumberUtil.instance.stringToInt(this)
}

/**
 *  字符串转Float
 * 
 * @author Icez
 */
fun String?.toSEFloat():Float{
    return NumberUtil.instance.stringToFloat(this)
}

/**
 *  字符串转Long
 * 
 * @author Icez
 */
fun String?.toSELong():Long{
    return NumberUtil.instance.stringToLong(this)
}

/**
 *  绝对路径图片进行压缩
 * 
 * @author Icez
 * @param context 上下文
 * @param quality 压缩率
 */
suspend fun String?.toSEAbsPathCompressImageForWebp(
    context: Context,
    quality: Int
): File? {
    return CompressUtil.instance.compressImageForWebp(context, this, quality)
}

/**
 *  保存数据
 * 
 * @author Icez
 * @param data 保存的数据
 */
suspend fun <T> String?.toSESaveDataForPreferences(data: T){
    DateStoreUtil.instance.saveDataForPreferences(this?:"",data)
}

/**
 *  获取数据
 * 
 * @author Icez
 */
suspend inline fun <reified T> String?.toSEGetSaveDataForPreferances():T?{
    return DateStoreUtil.instance.getSaveDataForPreferances<T>(this?:"")
}